package com.hsjk.szwj.module.pay.controller.app.order;

import cn.hutool.core.util.IdUtil;
import com.hsjk.szwj.framework.security.core.annotations.PreAuthenticated;
import com.hsjk.szwj.module.pay.controller.AbstractPayOrderController;
import com.hsjk.szwj.module.pay.dal.dataobject.CommonPayResult;
import com.hsjk.szwj.module.pay.service.IPayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/22 00:35
 **/
@Tag(name = "应用端 - 统一下单相关接口")
@RestController
@RequestMapping("/pay")
@Validated
public class UnifiedOrderController extends AbstractPayOrderController {
    @Resource
    private IPayService payService;

    /**
     * 统一下单接口
     **/
    @GetMapping("/unifiedOrder")
    @Operation(summary = "统一下单接口")
    @PreAuthenticated
    public CommonPayResult unifiedOrder(@RequestParam("orderId") Long orderId
            , @RequestParam("wayCode") String wayCode) {
        return CommonPayResult.success(payService.unifiedPay(orderId, wayCode));
    }

    public static void main(String[] args) {
        long snowflakeNextId = IdUtil.getSnowflakeNextId();
        System.out.println(snowflakeNextId);
    }
}
